﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using Emerald;

namespace RunnableProject.DrawableObjects
{
    class Board
    {
        #region Members

        private Emerald.Board _board;
        public Emerald.Board board{ get { return _board;} }

        #endregion

        #region Constructor

        public Board(Game g)
        {
            _board = g.GameState.Board;
        }

        #endregion

        #region Drawing functions

        public void Draw(Graphics g, BoardPoint selectedTile)
        {
            foreach (Tile tile in board.BoardArray.Tiles)
            {
                DrawTile(tile, g, (tile.Location == selectedTile));
            }
        }

        public void DrawTile(Tile tile, Graphics g, bool selected)
        {
            Brush brush = Brushes.Black;

            g.FillRectangle(brush, tile.Location.X * Globals.TileSize, tile.Location.Y * Globals.TileSize, Globals.TileSize, Globals.TileSize);
            g.DrawRectangle(Pens.LightGray, tile.Location.X * Globals.TileSize, tile.Location.Y * Globals.TileSize, Globals.TileSize, Globals.TileSize);

            if (tile.Piece != null)
            {
                Pen p = new Pen(Color.Black, 3.0f);
                Brush b = new SolidBrush(tile.Piece.Color.GetColor());

                if(selected)
                    b = new SolidBrush(tile.Piece.Color.GetSelectedColor());

                g.FillEllipse(b,
                              tile.Location.X * Globals.TileSize + (Globals.TileSize - Globals.PieceSize) / 2,
                              tile.Location.Y * Globals.TileSize + (Globals.TileSize - Globals.PieceSize) / 2,
                              Globals.PieceSize,
                              Globals.PieceSize);

                if (tile.Piece.State == EState.Marked)
                {
                    g.DrawEllipse(p,
                                  tile.Location.X * Globals.TileSize + (Globals.TileSize - Globals.MarkedPieceSize) / 2,
                                  tile.Location.Y * Globals.TileSize + (Globals.TileSize - Globals.MarkedPieceSize) / 2,
                                  Globals.MarkedPieceSize,
                                  Globals.MarkedPieceSize);
                }
            }

        }

        #endregion
    }
}
